package com.shop.service.impl;

import com.shop.entity.Role;
import com.shop.mapper.RoleMapper;
import com.shop.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int add(Role role) throws Exception {
        try {
            int add = roleMapper.add(role);
            return add;
        } catch (Exception e) {
          throw  new Exception("添加异常！");
        }

    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int update(Role role) throws Exception {
        try {
            int update = roleMapper.update(role);
            return update;
        } catch (Exception e) {
            throw  new Exception("更新异常！");
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int del(Role role) throws Exception {
        try {
            int del = roleMapper.del(role);
            return del;
        } catch (Exception e) {
            throw  new Exception("删除异常！");
        }
    }

    @Override
    public Role get(Role role) {
        return roleMapper.get(role);
    }

    @Override
    public List<Role> getList(Role role) {
        return roleMapper.getList(role);
    }
}
